package coc.core;

import java.io.Serializable;
import java.util.Date;

import com.gargoylesoftware.htmlunit.util.Cookie;

/**
 * 爬虫Cookie。
 */
public class CrawlerCookie implements Serializable {
	private String name;
	private String value;
	private String domain;
	private String path;
	private Date expires;
	private Boolean secure;
	private Boolean httpOnly;

	/**
	 * 构造方法。（转换JSON时需要）
	 */
	public CrawlerCookie() {
	}

	/**
	 * 构造方法。
	 * 
	 * @param cookie
	 *            HtmlUnit的Cookie
	 */
	public CrawlerCookie(Cookie cookie) {
		name = cookie.getName();
		value = cookie.getValue();
		domain = cookie.getDomain();
		path = cookie.getPath();
		expires = cookie.getExpires();
		secure = cookie.isSecure();
		httpOnly = cookie.isHttpOnly();
	}

	/**
	 * 转换为HtmlUnit的Cookie。
	 * 
	 * @return 返回HtmlUnit的Cookie。
	 */
	public Cookie toHtmlUnit() {
		return new Cookie(domain, name, value, path, expires, secure, httpOnly);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getDomain() {
		return domain;
	}

	public void setDomain(String domain) {
		this.domain = domain;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public Date getExpires() {
		return expires;
	}

	public void setExpires(Date expires) {
		this.expires = expires;
	}

	public Boolean getSecure() {
		return secure;
	}

	public void setSecure(Boolean secure) {
		this.secure = secure;
	}

	public Boolean getHttpOnly() {
		return httpOnly;
	}

	public void setHttpOnly(Boolean httpOnly) {
		this.httpOnly = httpOnly;
	}
}
